package org.example.back.service.user;

import org.example.back.entity.user.UserPlan;
import org.example.back.mapper.user.UserPlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.time.LocalDate;

@Service
public class UserPlanService {

    @Autowired
    private UserPlanMapper userPlanMapper;

    public boolean addPlan(UserPlan plan) {
        return userPlanMapper.insert(plan) > 0;
    }

    public boolean updatePlan(UserPlan plan) {
        return userPlanMapper.update(plan) > 0;
    }

    public boolean deletePlan(Integer userId, LocalDate plantime) {
        return userPlanMapper.delete(userId, plantime) > 0;
    }

    public UserPlan getPlanById(Integer id, Integer userId) {
        return userPlanMapper.findById(id, userId);
    }

    public List<UserPlan> getPlansByUserId(Integer userId) {
        return userPlanMapper.findByUserId(userId);
    }
}
